<?php
$isadmin=1;
include '../comm/config.php';
include_once 'check.php';
include_once 'data/config.inc.php';				//系统初始化文件
include_once 'include/function.admin.php';		//后台公用函数库

if($_GET['act']=='empty'){
    mysql_query("TRUNCATE TABLE `".$BIAOTOU."adminlog`");
}

$user 		= trim($_GET['user']);
$gettime=strtotime(trim($_GET['time']));
$page 			= $_GET ['page'] ? $_GET ['page'] : 1;
$page_size 		= 15;
$where="where 1=1";
if($user!=''){
	$where.=" and admin_name like '%" . $user."%'";
}
if($gettime!=''){
	$where.=" and time between " .$gettime." and ".($gettime+(24*60*60));
}
$sql_string = "select * from ".$BIAOTOU."adminlog ".$where."  order by time desc";
$total_nums = $db->getRowsNum ($sql_string);
$riji_list = $db->selectLimit ( $sql_string, $page_size, ($page - 1) * $page_size );

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>日记管理</title>
<link rel="stylesheet" type="text/css" href="../js/calendar/calendar-blue.css"/>
<script type="text/javascript" src="../js/calendar/calendar.js"></script>
<link href="article/images/css.css" rel="stylesheet" type="text/css">
<script src="include/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function doAction(a,id){
	ids = 0;
	if(a=='deleteAll'){
		if(confirm('请确认是否删除！')){
			$.ajax({
				url:'rizhi_del.php',
				type: 'POST',
				data:'act=cdelete&id='+getCheckedIds('checkbox'),
				success: function(data){
					window.location.href = window.location.href;
				}
			});
		}
	}
	if(a=='alldel'){
		if(confirm('请确认是否删除！')){
			$.ajax({
				url:'rizhi_del.php',
				type: 'POST',
				data:'act=alldel',
				success: function(data){
					window.location.href = window.location.href;
				}
			});
		}
	}
}

//全选/取消
function checkAll(o,checkBoxName){
	var oc = document.getElementsByName(checkBoxName);
	for(var i=0; i<oc.length; i++) {
		if(o.checked){
			oc[i].checked=true;	
		}else{
			oc[i].checked=false;	
		}
	}
	checkDeleteStatus(checkBoxName)
}
//检查有选择的项，如果有删除按钮可操作
function checkDeleteStatus(checkBoxName){
	var oc = document.getElementsByName(checkBoxName);
	for(var i=0; i<oc.length; i++) {
		if(oc[i].checked){
			document.getElementById('DeleteCheckboxButton').disabled=false;
			//document.getElementById('updateCategoryButton').disabled=false;
			//document.getElementById('selectCid').disabled=false;
			return;
		}
	}
	document.getElementById('DeleteCheckboxButton').disabled=true;
	//document.getElementById('updateCategoryButton').disabled=true;
	//document.getElementById('selectCid').disabled=true;
}

//获取所有被选中项的ID组成字符串
function getCheckedIds(checkBoxName){
	var oc = document.getElementsByName(checkBoxName);
	var CheckedIds = "";
	for(var i=0; i<oc.length; i++) {
		if(oc[i].checked){
			if(CheckedIds==''){
				CheckedIds = oc[i].value;	
			}else{
				CheckedIds +=","+oc[i].value;	
			}
			
		}
	}
	return CheckedIds;
}
</script>
</head>
<body topmargin="5" leftmargin="0">
<table width="100%" border="0" cellpadding="0" cellspacing="0" >
  <tr>
    <td valign="top">
    <form method="get" action="rizhi.php" style="margin:0">
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="serach">
        <tr>
          <td height="30" colspan="5" bgcolor="E9F2FB" class="bigtext"><strong>&nbsp;<img src="images/arrow.gif" width="16" height="22" align="absmiddle" /> 操作日志</strong></td>
        </tr>
        <tr>
          <td width="50" height="40" style="padding-left:2px"></td>
          <td width="230" style="padding-left:2px">管理员：
            <input title="输入要查询的用户名" name="user" type="text" value="<?=$user?>">
            <input type="submit" name="button" id="button" value="提交"></td>
          <td width="320">时间：
              <input name="time" type="text" id="time" value="">(例：2011-01-01)
              <input type="submit" name="button2" id="button2" value="提交">
              <script language="javascript" type="text/javascript">
					 date = new Date();
					Calendar.setup({
						inputField     :    "time",
						ifFormat       :    "%Y-%m-%d"
					});
				 </script>
          </td>
          <td width="300"><a href="rizhi.php">重置选项</a> <a href="rizhi.php?act=empty" onclick='return confirm("确定要清空日志?")'>清空日志</a></td>
        </tr>
      </table>
      </form>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_head">
        <tr>
          <td width="200" height="31">日记管理</td>
          <td align="right">&nbsp;</td>
        </tr>
      </table>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_form">
        <tr>
          <th width="4%"><input type="checkbox" name="checkbox11" value="checkbox" onClick="checkAll(this,'checkbox')"></th>
          <th width="10%" height="26">管理员</th>
          <th width="10%" height="26">操作IP</th>
          <th width="">操作</th>
          <th width="15%">时间</th>
        </tr>
        <?php
			 foreach ( $riji_list as $al ) {
		?>
        <tr>
          <td align="center">
          <input type="checkbox" name="checkbox"	value="<?php echo $al ['id'];?>" onClick="checkDeleteStatus('checkbox')"></td>
          <td height="26" align="center"><?php echo $al ['admin_name'];?></td>
          <td height="26" align="center"><?php echo $al ['ip'];?></td>
          <td align="center"><?php echo $al ['act_name'];?></td>
          <td height="26" align="center"><?php echo date("Y-m-d H:i:s",$al['time']);?></td>
        </tr>
          <?php
		}
		?>
      </table>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_footer">
        <tr>
          <td height="29" style="text-align: left; padding-left: 10px"><div style="float: left;">
              <input type="button" id="DeleteCheckboxButton" value="批量删除" disabled="disabled" onClick="doAction('deleteAll')">
              &nbsp;</div><div style="float: left;">
              <input type="button" id="DeleteCheckboxButton" value="全部删除"  onClick="doAction('alldel')"></div>
            <div style="float: right; padding-right: 50px"> <?php echo multi ( $total_nums, $page_size, $page, $mpurl, 0, 5 );?> </div></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>
